/**
 * 
 */
package com.xbang.core.web.tag;

import java.io.IOException;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.taglibs.standard.tag.el.core.ExpressionUtil;

import com.xbang.core.dao.search.component.SearchComponent;

/**
 * @author dev.zhang
 * 
 */
public class SearchBarTag extends BodyTagSupport {

	private static final long serialVersionUID = -5730334204193162367L;

	private static final Log logger = LogFactory.getLog(SearchBarTag.class);

	private String test;

	private String styleClass;

	public int doStartTag() throws JspException {
		if (StringUtils.isNotBlank(this.getTest())) {
			if ((Boolean) ExpressionUtil.evalNotNull("searchbar", "test", test, java.lang.Boolean.class, this, pageContext)) {
				printSearchBar();
			}
		} else
			printSearchBar();
		return super.doStartTag();
	}

	private void printSearchBar() {
		SearchComponent searchComponent = (SearchComponent) pageContext.getRequest().getAttribute("searchComponent");
		if (searchComponent == null || searchComponent.getSearchParameterNode() == null || searchComponent.getSearchParameterNode().isEmpty()) {
			return;
		}

		JspWriter writer = pageContext.getOut();
		try {
			Map<String, String> searchParameterNodes = searchComponent.getSearchParameterNode();
			writer.print("查询条件");
			for (Map.Entry<String, String> entry : searchParameterNodes.entrySet()) {
				writer.print("&nbsp;&nbsp;");
				writer.print(entry.getValue());
			}
		} catch (IOException ioe) {

		}

	}

	/**
	 * @return the styleClass
	 */
	public String getStyleClass() {
		return styleClass;
	}

	/**
	 * @param styleClass
	 *            the styleClass to set
	 */
	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}

	/**
	 * @return the test
	 */
	public String getTest() {
		return test;
	}

	/**
	 * @param test
	 *            the test to set
	 */
	public void setTest(String test) {
		this.test = test;
	}

}
